-
-
Notifications
You must be signed in to change notification settings - Fork 5.8k
preparations to remove context from repo struct #33893
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: main
Are you sure you want to change the base?
Conversation
modernize test
CommitsCountBetween is dead code
add context to commitsBetweenNotBase
Is it clear that the change is safe? If the For example: in |
There are already some deadlock problems like this So there could be 3 results of the "ctx" refactoring:
So ideally I think we should figure out and fix the deadlock problems before introducing unclear changes, and only introduce clear changes with necessary tests. The first clear and necessary change in my mind is to clarify the |
As far as I know this brings no functional change, it just changes/how when the context gets passed from: request -> open gitRepo with context -> function, to request -> open gitRepo -> function with context. For whatever reason it took me a far bit to understand what exactly you meant but I see what you're talking about now. // Note those are very basic and don't represent real operations
func SomeEndpoint(ctx *context.Context){
gitRepo,err:=git.openRepository(ctx.repo)
...:=gitRepo.SomeGitFunction(ctx)
func (repo ...) SomeGitFunction(ctx,...){
// It uses CatFileBatch underneath
...:=repo.CatFileBatch(ctx) // request scoped so might be stuck of a lot of data gets requested
} If it's meant to more usecase specific one I'd opt for local one but that's more wasteful probably: func SomeEndpoint(ctx *context.Context){
gitRepo,err:=git.openRepository(ctx.repo)
...:=gitRepo.SomeGitFunction(ctx)
func (repo ...) SomeGitFunction(ctx,...){
ctx,cancel:=context.WithCancel(ctx)
defer cancel()
// It uses CatFileBatch underneath
...:=repo.CatFileBatch(ctx) // as soon as it's useless it's removed
} I'll look into it more though input is welcome. |
Can you clarify what I can do to help with it? |
Maybe it needs a complete refactoring to make these functions overall right. TBH I don't quite understand the old design either. By reading the commit history briefly, I can see that at the beginning there was no "ctx", so the "cached batch checker" was right. Then, "ctx" support was added, then more and more places started using "ctx", then the "cached batch checker with ctx" might go wrong. There are still many technical debts to pay. 🤷♂️ IIRC (just FYI) there were other "ctx" patches
No idea, either some people did too much "defensive programming" and added unnecessary design, or there is a real case that it would happen in real world. 🤷♂️ |
I created #33934 to try to rework CatFile implementation. |
Thank you for the PR. Some updates here:
|
Can you point me in the more specific direction here? I don't see at a glance where ctx is stored in commit or commit cache - except indirectly via Repository struct. But overall my approach was more of finding where the embedded context was used and surfacing it. If there's a saner place to start with (which is not removing ctx from repository outright) I don't mind. |
The problematic design I just found is:
(ps: I just found it, I haven't really look into it or fully understood how the LastCommitCache works) |
So both of those are basically the same issue IMO - repository has ctx in it which it shouldn't have. We could either rework how the cache works so it doesn't carry repository reference - or continue this PR (in more PRs because it can become spaghetti to review fast) to remove the root case of all this - the ctx in repository struct. I haven't looked at how commit cache works either. |
Yep, similar, “Commit" is the main propagator.
TBH I think we need to refactor from deep to shallow (these "commit" and "cache" first, but not the parent contexts) If we start the refactoring from the "parent functions", it's unclear whether the deep ctx users would abuse the wrong ctx and cause more problems. So maybe we should |
Some more thoughts (might not be right, just FYI). It seems that the |
Some loose thoughts too: That cuts the LastCommitCache -> Repo -> Ctx embedding leaving leaving Repo (with LastCommitCache) -> Ctx. Also LastCommitCache doesn't use ctx by itself unless I missed it. |
first round of adding contexts to functions requiring it
trying keep it small'ish